package com.yuxl.common.socket.process;

import com.yuxl.common.core.domain.socket.Message;
import com.yuxl.common.core.utils.SocketUtil;
import com.yuxl.common.socket.annotation.SocketMessageMapping;
import com.yuxl.common.socket.domain.Msg;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;

/**
 * @Author : yuxl
 * @create 2025/7/10 下午2:22
 */
@Slf4j
@Component
public class TestProcess {

    @SocketMessageMapping("/chat")
    public Mono<String> chat(Message<Msg> message) {
        String username = message.getUser().username();
        return Mono.just("收到[" + username  + "]的消息: " + message.getData().getContent());
    }

    @SocketMessageMapping("/chatObj")
    public Msg chatObj(Message<Msg> message) {
        String username = message.getUser().username();
        Msg msg = new Msg();
        msg.setContent("收到[" + username  + "]的消息msg: " + message.getData().getContent());
        return msg;
    }

    @SocketMessageMapping("/chatByUserName")
    public Mono<Void> chatByUserName(Message<Msg> message) {
        String username = message.getUser().username();
        return SocketUtil.sendToUser(username,"收到[" + username  + "]的消息2: " + message.getData().getContent())
                .then();
    }
}
